package com.itheima.dao;

import com.itheima.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface OrderDao {

    @Insert("insert into t_order" +
            " values " +
            "(null,#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void addOrder(Order order);

    @Select("select * from t_order where member_id=#{member_id} and orderDate=#{orderDate} and setmeal_id=#{setmeal_id}")
    public List<Order> searchOrderByMemberId(@Param("member_id") Integer memberId, @Param("orderDate") Date date, @Param("setmeal_id") Integer setmealId);

    @Select("select m.name member,o.orderDate orderDate,o.orderType orderType,s.name setmeal from t_member m,t_order o,t_setmeal s where o.id=#{id} and o.setmeal_id=s.id and o.member_id=m.id")
    public Map searchOrderById(@Param("id") Integer id);
}
